<?php
namespace app\api\model;

use think\Model;

class NoticeModel extends Model{
	//表名
	protected $table = 'ly_notice';

	/**
	 * [getNotice 平台公告]
	 * @return [type] [description]
	 */
	public function getNotice(){
		//获取公告列表
		$param 		= input('post.');

		$where = 'a.state=1 ';
		if(isset($param['gropid']) && $param['gropid']){
			$where.=" and a.gropid={$param['gropid']}";
		}
		//每页记录数
		$pageSize	= (isset($param['pagesize']) and $param['pagesize']) ? $param['pagesize'] : 10;
		//当前页
		$page		= (isset($param['page']) and $param['page']) ? $param['page'] : 1;


	
		
		$data=$this->alias('a')->field('a.id,a.title,a.add_time')->where($where)
		->order('add_time','desc')
		->paginate($pageSize)
        ->toArray();
		

		foreach ($data['data'] as $key => &$value) {
		    $value['add_time'] = date('Y-m-d H:i:s',$value['add_time']);
		}
		return $data;
	}

	/**
	 * [getNotice 平台公告]
	 * @return [type] [description]
	 */
	public function getNoticeDetail(){
		//获取公告列表
		$id 		= input('post.id');

		$notice = $this->where(array('state'=>1,'id'=>$id))->find();
		if($notice){
			$notice['add_time'] = date('Y-m-d H:i:s',$notice['add_time']);
			$notice['content'] = htmlspecialchars_decode($notice['content']);
			$notice['cover_img']=$notice['cover_img']?($_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$notice['cover_img']):'';
		}
		return $notice;
	}

}